// pages/home/home.js
var app=getApp();
var util=require("../../utils/util");
var home=require("../../api/home");
var group=require("../../api//group");
var config=require("../../api/config");
var QQMapWX = require('../../utils/qqmap-wx-jssdk');


Page({
  /*页面的初始数据*/
  data: {
    navColor: "#fff",
    showHome: true,
    address: "佛山市",
    hot_list: [],
    hide: false,
    top_height: "",
    top_list: [{icon:"/images/icon134.png",title:"附近名师"},{icon:"/images/icon135.png",title:"附近机构"}],
    class_list: ["","","","","","","","","",""],
    banner_list:[],
    current_index: 0,
    nav_list: [{name:'精选课'},{name:'体验课'},{name:'拼团课'}],
    point_list: ["优质课程","免费优惠","折扣秒杀"],
    nav_index: 0,
    nav_id: '',
    heights: [false,true,true,true],
    com_data1: [],
    com_data2: [],
    com_data3: [],
    com_data4: [],
    scroll_arr: [0,0,0,0],
    show_scroll: true,
    scroll_top: 0,
    fix: false,
    currentPage1: 1,
    currentPage2: 1,
    currentPage3: 1,
    currentPage4: 1,
    pageSize: 5,
    hasMoreData1: true,
    hasMoreData2: true,
    hasMoreData3: true,
    hasMoreData4: true,
    latitude: 22.820794,
    longitude: 113.284565,
    adr_info: '',
    pref_list: [],
    pref_text: ['立减券','满减券','礼品券','','平台券'],
    timeout: true,
    token: '',
    login: false,
    login_mask: true,
    activ_info: '',
    activity_mask: true,
    count: '',
    activ_count: 0,
    root: true,
    activity_id: '1344172560662351873'
  },
  /*生命周期函数--监听页面加载*/
  onLoad: function (options) {
    var that = this,sysinfo = wx.getSystemInfoSync(),pixelRate=sysinfo.windowWidth/750,statusBarHeight=sysinfo.statusBarHeight,parentId='';
    that.setData({pixelRate:pixelRate,statusBarHeight:statusBarHeight})
    wx.getStorage({
      key: 'token',
      success:function(res){
        that.setData({token:res.data})
        //
        that.is_login(res.data)
      },
      fail:function(){
        that.is_login('')
      }
    })
    if(options.scene){
      parentId=decodeURIComponent(options.scene)
      wx.setStorageSync('parentId', decodeURIComponent(options.scene))
    }
    // 授权位置加载数据
    that.get_user_location(parentId)
  },
  //重新选择定位
  choose_location:function(){
    var that=this;
    wx.getSetting({
      success: function (res) {
        if(res.authSetting["scope.userLocation"]){
          that.change_location()
        }else{
          // 重新授权
          wx.openSetting({
            success:function(res){
              if (res.authSetting["scope.userLocation"]) {
                that.change_location()
              }
            }
          })
        }
      }
    })
  },
  change_location:function(){
    var that=this;
    wx.chooseLocation({
      success:function (res) {
        // console.log(res)
        var latitude=res.latitude,longitude=res.longitude;
        that.setData({address:res.name,latitude:latitude,longitude:longitude})
        that.init_home();
        that.get_address_sdk(latitude,longitude,2)
        that.get_all_data()
      },
      fail:function(res){
        console.log("---重新定位失败---")
        // util.page_show_toast('重新定位失败',1500)
      }
    })
  },
  // 搜索框
  nav_search:function(){
    wx.navigateTo({
      url: '../search/search',
    })
  },
  // 热搜
  search_keyword:function(e){
    var word=e.currentTarget.dataset.word;
    wx.navigateTo({
      url: '../searchlist/searchlist?name=' + word,
    })
  },
  // 顶部跳转
  nav_top_to:function(e){
    var index=e.currentTarget.dataset.index,id=e.currentTarget.dataset.id;
    if(index==0){
      wx.navigateTo({
        url: '../famousMaster/famousMaster',
      })
      // 事件统计
      app.td_app_sdk.event({
        id: 'famousMaster',
        label: '附近名师',
        params: {
          key1: '附近名师'
        }
      })
    }else{
      wx.navigateTo({
        url: '../nearMech/nearMech',
      })
      // 事件统计
      app.td_app_sdk.event({
        id: 'nearMech',
        label: '附近机构',
        params: {
          key1: '附近机构'
        }
      })
    }
  },
  // 兴趣教育
  nav_class:function(e){
    var id=e.currentTarget.dataset.id,name=e.currentTarget.dataset.name;
    wx.navigateTo({
      url: '../classifyList/classifyList?id='+id+'&name='+name,
    })
    // 事件统计
    app.td_app_sdk.event({
      id: 'interest',
      label: '兴趣教育',
      params: {
        key1: name
      }
    })
  },
  // 学科辅导
  nav_subject:function(e){
    var that=this,sub_id=that.data.sub_id;
    var id=e.currentTarget.dataset.id,name=e.currentTarget.dataset.name;
    var type=name=="全学科"?2:1;
    wx.navigateTo({
      url: '../subject/subject?id='+sub_id+'&sid='+id+'&name='+name+'&type='+type,
    })
    // 事件统计
    app.td_app_sdk.event({
      id: 'subject',
      label: '学科辅导',
      params: {
        key1: name
      }
    })
  },
  // 轮播图
  swiper_change:function(e){
    this.setData({current_index: e.detail.current})
  },
  // banner跳转
  jump_to:function(e){
    var that=this,banner_list=that.data.banner_list;
    var index=e.currentTarget.dataset.index;
    var title=banner_list[index].title,small=banner_list[index].appletPage,html=banner_list[index].h5Link,adulr=banner_list[index].adUrl;
    if(small){
      if(small.indexOf("http")>-1){
        wx.navigateTo({
          url: '../../mypage/webImage/webImage?title='+title+'&url='+small+'&page='+adulr,
        })
      }else{
        wx.navigateTo({
          url: small,
        })
      }
    }
    if(html){
      wx.navigateTo({
        url: '../../mypage/webView/webView?index=4'+'&title='+title+'&url='+html,
      })
    }
  },
  // 课程类型导航
  change_index:function(e){
    var that = this, nav_index = that.data.nav_index,scroll_arr=that.data.scroll_arr,fix=that.data.fix;
    var index = e.currentTarget.dataset.index,id=e.currentTarget.dataset.id;
    if(nav_index != index){
      that.setData({nav_index:index,nav_id:id})
      if(index==0&&that.data.com_data1.length==0){
        that.get_cour_list(id,index)
      }
      if(index==1&&that.data.com_data2.length==0){
        that.get_cour_list(id,index)
      }
      if(index==2&&that.data.com_data3.length==0){
        // that.get_cour_list(id,index)
        that.get_group_list()
      }
      // if(index==3&&that.data.com_data4.length==0){
      //   that.get_group_list()
      // }
      if(fix){
        that.setData({show_scroll:false})
        if(scroll_arr[0]>0){
          wx.pageScrollTo({
            scrollTop: scroll_arr[index],
            duration: 10
          })
        }
        setTimeout(function(){that.setData({show_scroll: true})},1000)
      }
    }
  },
  // 滚动定位
  onPageScroll:function(e){
    var that = this,scroll_top = that.data.scroll_top,nav_index=that.data.nav_index,scroll_arr=that.data.scroll_arr,show_scroll=that.data.show_scroll;
    var scroll = e.scrollTop;
    // console.log(scroll,scroll_top)
    if(scroll>scroll_top-100){
      if(!that.data.fix){
        that.setData({fix: !that.data.fix})
      }
      if(show_scroll){
        for(var i=0;i<scroll_arr.length;i++){
          scroll_arr[nav_index]=scroll;
          if(scroll_arr[i] == 0){
            scroll_arr[i]=scroll_top;
          }
        }
      }
    }else{
      if(that.data.fix){
        that.setData({fix: !that.data.fix})
      }
    }
    if(scroll>=30){
      if(!that.data.hide){
        that.setData({hide: !that.data.hide})
      }
    }else{
      if(that.data.hide){
        that.setData({hide: !that.data.hide})
      }
    }
  },
  // 下拉刷新
  onPullDownRefresh:function(){
    // wx.startPullDownRefresh()
    var that=this;
    that.init_home();
    // 刷新
    setTimeout(()=>{wx.stopPullDownRefresh()},500)
    that.get_all_data()
    that.get_home_banner_list()
  },
  // 下拉重置数据
  init_home:function(){
    var that=this;
    that.setData({
      heights: [false,true,true,true],
      class_list: ["","","","","","","","","",""],
      banner_list: [],
      nav_list: [{name:'精选课'},{name:'体验课'},{name:'拼团课'}],
      point_list: ["优质课程","免费优惠","折扣秒杀"],
      nav_index: 0,
      scroll_arr: [0,0,0,0],
      com_data1: [],
      com_data2: [],
      com_data3: [],
      com_data4: [],
      show_scroll: true,
      currentPage1: 1,
      currentPage2: 1,
      currentPage3: 1,
      currentPage4: 1,
      pageSize: 10,
      hasMoreData1: true,
      hasMoreData2: true,
      hasMoreData3: true,
      hasMoreData4: true
    });
  },
  // 触底
  onReachBottom:function(){
    var that=this,id=that.data.nav_id,show_scroll=that.data.show_scroll,nav_index=that.data.nav_index;
    var hasMoreData=nav_index==0?that.data.hasMoreData1:nav_index==1?that.data.hasMoreData2:nav_index==2?that.data.hasMoreData3:that.data.hasMoreData4;
    if(show_scroll){
      if(hasMoreData){
        if(nav_index==2){
          that.get_group_list()
        }else{
          that.get_cour_list(id,nav_index)
        }
      }else{
        util.page_show_toast('没有更多了',1500)
      }
    }
  },
  // 关闭优惠券提示
  close_rem_pop:function(e){
    var that=this;
    var id=e.currentTarget.dataset.id,type=e.currentTarget.dataset.type;
    that.setData({timeout:!that.data.timeout})
    if(type!=4){
      wx.navigateTo({
        url: '../mechDetail/mechDetail?id='+id+'&status=10',
      })
    }
  },
  // 优惠券适用
  open_more:function(e){
    var that = this,pref_list=that.data.pref_list;
    var index=e.currentTarget.dataset.index;
    if(pref_list[index].couponWay==4){
      var businessNames=pref_list[index].businessNames?pref_list[index].businessNames:'';
      wx.showToast({
        title: pref_list[index].couponUsingRange==1?'适用机构：'+businessNames:'适用平台全部机构',
        icon: 'none',
        duration: 3000
      })
    }else{
      var businessName=pref_list[index].businessName?pref_list[index].businessName:'';
      var courseNames=pref_list[index].courseNames?pref_list[index].courseNames:'';
      wx.showToast({
        title: pref_list[index].couponUsingRange==1?'适用'+businessName+'以下课程：'+courseNames:'适用'+businessName+'全部课程',
        icon: 'none',
        duration: 3000
      })
    }
  },
  // 禁止触摸穿透
  return:function(){},
  // 登录刷新
  onShow:function(){
    var that=this;
    if(app.globalData.login){
      app.globalData.login=false;
      app.globalData.change_dom=false;
      app.globalData.change_table=false;
      that.setData({login:true,token:wx.getStorageSync('token')});
      // that.get_activity_pref();
    }
    if(that.data.login){
      // that.get_activity_pref();
    }
  },
  // 渲染完成
  onReady: function () {
    var that = this;
    var query = wx.createSelectorQuery();
    query.selectAll('.search_wrap').boundingClientRect(function (res) {
      // console.log(res)
      that.setData({ margin_height: res[0].bottom })
    }).exec()
    query.selectAll('.banner_box').boundingClientRect(function (res) {
      // console.log(res)
      that.setData({ scroll_top: res[0].bottom })
    }).exec()
    query.selectAll('.search_hot').boundingClientRect(function (res) {
      // console.log(res)
      that.setData({ top_height: res[0].top })
    }).exec()
  },
  // 分享
  onShareAppMessage:function(){
    var that=this,name=wx.getStorageSync('userinfo')?wx.getStorageSync('userinfo').nickName:'';
    return{
      title: name+'邀请您一起关注家巴啦',
      path: '/pages/home/home',
      imageUrl: 'https://ossdev0.jiabala.com/xaSpNcZEmBSRd'
    }
  },
  // 定位
  get_user_location:function(parentId){
    var that=this;
    wx.showLoading({title:"加载中"})
    wx.getLocation({
      type: 'gcj02',
      isHighAccuracy: true,
      success:function (res) {
        // console.log(res)
        var latitude=res.latitude,longitude=res.longitude;
        that.setData({latitude:latitude,longitude:longitude})
        // 
        that.get_all_data();
        that.get_address_sdk(latitude,longitude,1,parentId)
      },
      fail: function(){
        //
        that.get_all_data();
        that.get_address_sdk(that.data.latitude,that.data.longitude,1,parentId)
      }
    })
  },
  // 腾讯sdk解析地址
  get_address_sdk:function(latitude,longitude,type,parentId){
    wx.showLoading()
    var that=this;
    var qqmapsdk = new QQMapWX({
      key: 'EVZBZ-2EPWR-JGZWX-WQCQ7-AAXUE-NKBLV' // key
    });  
    qqmapsdk.reverseGeocoder({
      location: {
        latitude: latitude,
        longitude: longitude
      },
      success:function(res){
        wx.hideLoading()
        // console.log(res)
        var info=res.result,login=that.data.login;
        info.ad_info.city_code=info.ad_info.city=="北京市"?'110100':info.ad_info.city=="天津市"?'120100':info.ad_info.city=="上海市"?'310100':info.ad_info.city=="重庆市"?'500100':info.ad_info.city_code.split(info.ad_info.nation_code)[1];
        info.ad_info.lat=latitude;
        info.ad_info.lng=longitude;
        info.ad_info.address=info.address;
        info.ad_info.town=info.address_reference.town.title;
        wx.setStorageSync('city', info.ad_info)
        that.setData({adr_info:info.ad_info})
        if(type==1){
          that.setData({address:info.address_component.street_number})
        }
        if(parentId){
          wx.navigateTo({
            url: '../login/login?parentId='+parentId,
          })
        }
        //
        that.get_home_banner_list();
        // 获取9月份活动数据
        // if(login){
        //   that.get_activity_pref();
        // }
      },
      fail:function(res){
        //
        that.get_home_banner_list();
        console.log("---地址解析失败---")
      }
    })
  },
  // 获取首页接口数据
  get_all_data:function(){
    var that=this;
    wx.showLoading({title: '加载中'})
    //
    that.get_hot_search();
    that.get_home_classify_list();
    that.get_home_nav();
    that.get_activity_type();
  },
   // 热门搜索
   get_hot_search:function(){
    wx.showLoading({title: '加载中'})
    var that=this;
    home.get_hot_search().then(res=>{
      if(res.data.code==200){
        var list=res.data.data;
        that.setData({hot_list:list})
      }
    })
  },
  // 区分兴趣/学科
  get_home_classify_list:function(){
    var that=this,arr1=[],arr2=[];
    home.get_home_classify_list().then(res=>{
      if(res.data.code==200){
        var list=res.data.data;
        for(var i=0;i<list.length;i++){
          if(list[i].position==1){
            arr1.push(list[i])
          }else{
            arr2.push(list[i])
          }
          if(list[i].name=="学科辅导"){
            that.get_cate_list(list[i].id)
            that.setData({sub_id:list[i].id})
          }
        }
        
        that.setData({class_list: arr2})
      }
    })
  },
  // 获取学科辅导分类
  get_cate_list:function(id){
    var that=this;
    var params={
      "parentId": id,
      "flagEnable": 1
    }
    home.get_cate_list(params).then(res=>{
      if(res.data.code==200){
        var list=res.data.data,arr=[];
        for(var i=0;i<list.length;i++){
          if(list[i].name=="语文"||list[i].name=="数学"||list[i].name=="英语"||list[i].name=="全学科"){
            arr.push(list[i])
          }
        }
        that.setData({sub_list:arr})
      }
    })
  },
  // 获取banner
  get_home_banner_list:function(){
    var that=this,adr_info=that.data.adr_info;
    var params={
      "provinces": adr_info?adr_info.province:'广东省',
      "citys": adr_info?adr_info.city:'佛山市',
      "showRange": 1,
      "typeId": 1,
      "enable": 1,
      "belongToPage": 1
    }
    home.get_home_banner_list(params).then(res=>{
      if(res.data.code==200){
        var list=res.data.data;
        that.setData({banner_list:list})
      }
    })
  },
  // 获取课程类型导航
  get_home_nav:function(){
    var that=this;
    var params={"currentPage": 1,"pageSize": 20}
    home.get_home_nav(params).then(res=>{
      if(res.data.code==200){
        var list=res.data.data.records;
        for(var i=0;i<list.length;i++){
          if(list[i].name=="在线课"){
            list.splice(i,1);
          }
          if(list[i].name=="常规课"){
            list.splice(i,1);
          }
        }
        that.setData({nav_list: list,nav_id:list[0].id});
        that.get_cour_list(list[0].id,0)
      }
    })
  },
  // 获取课程列表
  get_cour_list:function(id,index){
    wx.showLoading({title:"加载中"})
    var that=this,currentPage=index==0?that.data.currentPage1:index==1?that.data.currentPage2:that.data.currentPage3,pageSize=that.data.pageSize,heights=that.data.heights;
    var params={
      "currentPage": currentPage,
      "pageSize": pageSize,
      "courseNatureId": id,
      "status": 3,
      "lat": that.data.latitude,
      "lng": that.data.longitude
    }
    home.get_cour_list(params).then(res=>{
      if(res.data.code==200){
        var list=res.data.data.records;
        for(var i=0;i<list.length;i++){
          list[i].introducePictures=list[i].introducePictures?list[i].introducePictures.split(","):'';
          list[i].score=list[i].score?list[i].score.toFixed(1):'5.0';
          list[i].startTime=list[i].startTime?util.formatTime_age(new Date(list[i].startTime)):'';
          list[i].space=list[i].distance>1000?(list[i].distance/1000).toFixed(2):list[i].distance;
          list[i].labelName=list[i].labelName?list[i].labelName.split(","):''
          list[i].teacherProfile=list[i].teacherProfile?(list[i].teacherProfile.indexOf("undefined")>-1?'':list[i].teacherProfile.split(",")):'';
          list[i].sellCount=list[i].sellCount?list[i].sellCount:0
        }
        if(index==0){
          var cour_list = that.data.com_data1;
          cour_list = util.extend(cour_list, list)
          if (list.length < pageSize) {
            that.setData({
              com_data1: cour_list,
              hasMoreData1: false
            })
          } else {
            that.setData({
              com_data1: cour_list,
              hasMoreData1: true,
              currentPage1: currentPage + 1
            })
          }
        }else if(index==1){
          var cour_list = that.data.com_data2;
          cour_list = util.extend(cour_list, list)
          if (list.length < pageSize) {
            that.setData({
              com_data2: cour_list,
              hasMoreData2: false
            })
          } else {
            that.setData({
              com_data2: cour_list,
              hasMoreData2: true,
              currentPage2: currentPage + 1
            })
          }
        }else{
          var cour_list = that.data.com_data3;
          cour_list = util.extend(cour_list, list)
          if (list.length < pageSize) {
            that.setData({
              com_data3: cour_list,
              hasMoreData3: false
            })
          } else {
            that.setData({
              com_data3: cour_list,
              hasMoreData3: true,
              currentPage3: currentPage + 1
            })
          }
        }
        heights[index]=false;
        setTimeout(()=>{that.setData({heights:heights})},500)
      }
    })
  },
  // 拼团课程列表
  get_group_list:function(){
    wx.showLoading({title:"加载中"})
    var that=this,currentPage=that.data.currentPage3,pageSize=that.data.pageSize,heights=that.data.heights;
    var params={
      "currentPage": currentPage,
      "pageSize": pageSize,
      "activityType": 1,
      "name": '',
      "status": 2,
      "delFlag": 0,
      "upDownShelves": 1,
      "lat": that.data.latitude,
      "lng": that.data.longitude
    }
    group.get_group_list(params).then(res=>{
      if(res.data.code==200){
        var list=res.data.data.records;
        for(var i=0;i<list.length;i++){
          list[i].introducePictures=list[i].courseAvatar?list[i].courseAvatar.split(","):'';
          list[i].score=list[i].score?list[i].score.toFixed(1):'5.0';
          list[i].space=list[i].distance>1000?(list[i].distance/1000).toFixed(2):list[i].distance;
          // list[i].teacherLabel=list[i].teacherLabel?(list[i].teacherLabel.indexOf("undefined")>-1?'':list[i].teacherLabel.split(",")):'';
        }
        var cour_list = that.data.com_data3;
        cour_list = util.extend(cour_list, list)
        if (list.length < pageSize) {
          that.setData({
            com_data3: cour_list,
            hasMoreData3: false
          })
        } else {
          that.setData({
            com_data3: cour_list,
            hasMoreData3: true,
            currentPage3: currentPage + 1
          })
        }
        heights[2]=false;
        setTimeout(()=>{that.setData({heights:heights})},500)
      }
    })
  },
  // 判断是否登录(token是否失效)
  is_login:function(token){
    var that=this;
    config.is_login(token).then(res=>{
      if(res.data.code==200){
        if(!res.data.data){
          wx.removeStorageSync('token');
          var wx_info=wx.getStorageSync('unionId'),login_info=wx.getStorageSync('login_info');
          if(wx_info){
            that.wx_login(wx_info);
          }
          if(login_info){
            that.login_by_password(login_info);
          }
        }else{
          that.setData({login:true})
          console.log("---token未失效---")
        }
      }
    })
  },
  // 微信登录获取token信息
  wx_login:function(wx_info){
    var that=this;
    var params={
      "unionId": wx_info.unionId,
      "openId": wx_info.openId,
      "bindType": "1",
      "thirdAppId": app.globalData.appId
    };
    config.wx_login(params).then(res=>{
      if(res.data.code==200){
        var info=res.data.data;
        that.setData({login:true,token:info.token})
        wx.setStorageSync('userinfo', info.userInfo)
        wx.setStorageSync('token', info.token)
        //
        that.get_pref_time(info);
      }
    })     
  },
  // 账号登录获取token信息
  login_by_password:function(info){
    var that=this;
    config.login_by_password({"phone":info.phone,"password":info.password}).then(res=>{
      if(res.data.code==200){
        var info=res.data.data;
        that.setData({login:true,token:info.token})
        wx.setStorageSync('userinfo', info.userInfo)
        wx.setStorageSync('token', info.token)
        //
        that.get_pref_time(info);
      }
    })
  },
  // 优惠券过期提醒
  get_pref_time:function(info){
    var that=this,pref_text=that.data.pref_text;
    var params={
      "nowTime": new Date().getTime()
    };
    config.get_pref_time(params,info.token).then(res=>{
      if(res.data.code==200){
        var list=res.data.data;
        if(list&&list.length>0){
          for(var i=0;i<list.length;i++){
            list[i].couponEndTime=util.formatTime_age(new Date(list[i].couponEndTime))
            list[i].couponWayName=pref_text[list[i].couponWay]
          }
          that.setData({pref_list:list,timeout:false})
        }
      }
    })
  },
  // 查看活动是否过期
  get_activity_type:function(){
    var that=this,activity_id=that.data.activity_id;
    var params={
      "activityId": activity_id
    }
    config.get_activity_type(params).then(res=>{
      if(res.data.code==200){
        if(res.data.data){
          that.setData({activity_type:true})
        }else{
          that.setData({activity_type:false})
          app.globalData.activity_type=false
        }
      }
    })
  },
  // 活动(9月)
  // 未登录
  open_login_mask:function(){
    this.setData({login_mask:false})
  },
  close_login_mask:function(){
    this.setData({login_mask:true})
  },
  nav_login:function(){
    this.close_login_mask();
    wx.navigateTo({
      url: '../login/login',
    })
  },
  // 已登录
  open_activ_mask:function(){
    this.setData({activity_mask:false});
  },
  close_activ_mask:function(){
    this.setData({activity_mask:true});
  },
  // 单张领取
  user_get_pref:function(e){
    var that=this,info=that.data.activ_info;
    var id=e.currentTarget.dataset.id;
    that.get_one_pref(info.id,id)
  },
  // 一键领取
  user_get_all_pref:function(){
    var that=this,info=that.data.activ_info,root=that.data.root;
    if(root){
      that.get_all_pref(info.id)
    }else{
      that.close_activ_mask()
    }
  },
  // 首页优惠券活动
  get_activity_pref:function(){
    var that=this,info=that.data.adr_info,token=that.data.token;
    var params={
      "province": info.province,
      "city": info.city,
      "area": info.district,
      "town": info.town,
      "status": 2
    }
    config.get_activity_pref(params,token).then(res=>{
      if(res.data.code==200){
        var list=res.data.data,info=res.data.data[list.length-1],arr_no_apply=[],arr_apply=[],root=true;
        for(var i=0;i<info.platformVolumes.length;i++){
          // 已领取
          if(info.platformVolumes[i].isReceive==1){
            arr_no_apply.push(info.platformVolumes[i])
          }
          // 已使用
          if(info.platformVolumes[i].isReceive==2){
            arr_apply.push(info.platformVolumes[i])
          }
        }
        if((arr_no_apply.length+arr_apply.length)==info.platformVolumes.length){
          root=false
        }
        that.setData({activ_info:info,activ_count:info.platformVolumes.length,count:arr_no_apply.length,root:root});
      }
    })
  },
  // 单张领取
  get_one_pref:function(aid,vid){
    var that=this,token=that.data.token;
    var params={
      "activityId": aid,
      "volumeId": vid
    }
    config.get_one_pref(params,token).then(res=>{
      if(res.data.code==200){
        
      }
    })
  },
  // 一键领取
  get_all_pref:function(id){
    var that=this,token=that.data.token;
    var params={
      "activityId": id
    }
    config.get_all_pref(params,token).then(res=>{
      if(res.data.code==200){
        that.close_activ_mask();
        util.page_show_toast("领取成功",2000)
        // 刷新下活动改变优惠券状态
        that.get_activity_pref();
      }
    })
  },
})